package com.medical.data.controller;

import com.medical.data.domain.DataCollector;
import com.medical.data.domain.FormTemplate;
import com.medical.data.domain.Patient;
import com.medical.data.service.DataCollectorService;
import com.medical.data.service.FormTemplateService;
import com.medical.data.service.PatientService;
import com.medical.data.service.PatientTemplateService;
import com.medical.data.utils.Result;
import com.medical.data.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/front/data")
@Api(description = "数据查询")
@Slf4j
public class DataController {
    @Autowired
    private FormTemplateService formTemplateService;
    @Autowired
    private PatientService patientService;
    @Autowired
    private PatientTemplateService patientTemplateService;
    @Autowired
    private DataCollectorService dataCollectorService;


    @ApiOperation("获取数据接口")
    @PostMapping("/getData/{projectId}")
    public Result DataCollect(@PathVariable @NotBlank(message = "项目id不可为空") String projectId) {
        log.info("/front/data/getData参数========>{}", projectId);
        List<AllFormsVo> list = formTemplateService.getAllFormByProjectId(projectId);
        return Result.ok().data("result", list);
    }

    @ApiOperation("根据节点查询患者接口")
    @PostMapping("/getPatientByNodes/{nodeId}")
    public Result getPatientByNodes(@PathVariable @NotBlank(message = "项目id不可为空") String nodeId) {
        log.info("/front/data/getPatientByNodes参数========>{}", nodeId);
        List<Patient> list = new ArrayList<>();
        list = patientService.getPatientsByIds(patientTemplateService.getPatientByNode(nodeId));
        return Result.ok().data("patients", list);
    }

    @ApiOperation("获得第一行数据")
    @PostMapping("/getFirstLine")
    public Result getFirstLine() {
        log.info("/front/data/getFirstLine参数========>{}");
        Map<String, String> map = dataCollectorService.getFirstLine();
        return Result.ok().data("firstLine",map);
    }

    @ApiOperation("获得第二行数据")
    @PostMapping("/getSecondLine")
    public Result getSecondLine() {
        log.info("/front/data/getFirstLine参数========>{}");
        Map<String, String> map = dataCollectorService.getSecondLine();
        return Result.ok().data("secondLine",map);
    }

    @ApiOperation("获得数据")
    @PostMapping("/getLastData")
    public Result getLastData() {
        log.info("/front/data/getLastData参数========>{}");
        List<LastDataVo> list = dataCollectorService.getLastData();
        return Result.ok().data("lastData",list);
    }

    @ApiOperation("获得数据")
    @PostMapping("/getAgeData")
    public Result getAgeData() {
        log.info("/front/data/getAgeData参数========>{}");
        List<PatientAgeVo> list = dataCollectorService.getAgeData();
        return Result.ok().data("Age",list);
    }

    @ApiOperation("获得医院收集数据信息")
    @PostMapping("/getHsData")
    public Result getHsData() {
        log.info("/front/data/getHsData参数========>{}");
        List<HsDataVo> list = dataCollectorService.getHsData();
        return Result.ok().data("hsData",list);
    }

    @ApiOperation("获得科室收集数据信息")
    @PostMapping("/getKsData")
    public Result getKsData() {
        log.info("/front/data/getKsData参数========>{}");
        List<KsDataVo> list = dataCollectorService.getKsData();
        return Result.ok().data("ksData",list);
    }
}
